const {ccclass, property} = cc._decorator;

@ccclass
export default class birdControl extends cc.Component {

    // LIFE-CYCLE CALLBACKS:
    // 小鸟方向
    @property(cc.Vec2)
    dir:cc.Vec2 = cc.v2(0, 100);
    // 小鸟刚体
    rg:cc.RigidBody

    hasPass: number = 0;

    onLoad () {
        this.rg = this.getComponent(cc.RigidBody);
    }

    // 小鸟飞行
    fly() {
        // 向上添加线性速度
        this.rg.linearVelocity = this.dir;
    }

    start () {
        this.node.on(cc.Node.EventType.TOUCH_START, (e: cc.Touch)=> {
            this.fly();
        }, this)
    }

    update (dt) {}

    // 开始碰撞
    onBeginContact(contact, self, other) {
        // 获取碰撞物体
        let otherTag = other.tag;
        if (otherTag == 3) {
            this.hasPass++;
            console.log('已经闯过' + this.hasPass + '关');
            
        }
    }

    // 结束碰撞
    onEndContact(contact, self, other) {

    }
}
